/* a template for creating new Tuxpaint magic plugins quickly

*/
#define DEBUG 1		// 1 during development 0 at other times

#include <stdio.h>
#include <string.h>  // For "strdup()"
#include <libintl.h>  // For "gettext()"

#ifdef WIN32
#elif __BEOS__
#elif __APPLE__
#else
# include "sys/stat.h" // for mkdir()
# include "sys/time.h" // for gettimeofday()
#endif

#include "tp_magic_api.h"  // Tux Paint "Magic" tool API header
#include "SDL_image.h"  // For IMG_Load(), to load our PNG icon

#ifndef NOSOUND
# include "SDL_mixer.h"  // For Mix_LoadWAV(), to load our sound effects
#endif

enum
{
	TOOL_TEMPLATE,
	NUM_TOOLS
};

typedef struct {
	const char *icon_filename;
	const char *snd_filename_start;
	const char *snd_filename_stop;
	const char *name;
	const char *desc;
} toolsstru;

toolsstru tools[NUM_TOOLS] = 
{
	{
		"slippery.png",
		"36788_farbin_klank_1.ogg",
		"",
		gettext_noop ( "Experiment"),
		gettext_noop ( "Adds experimental behaviour to the current picture."),
	}
};

/* --------------------- */
Uint32 template_api_version ( void )
{
#ifdef DEBUG
	fprintf( stderr, "template_api_version\n");
#endif
	return TP_MAGIC_API_VERSION;
}

int template_init ( magic_api * api )
{
	return 1;
}


/* --------------------- */
int template_get_tool_count ( magic_api * api )
{
#ifdef DEBUG
	fprintf( stderr, "template_get_tool_count\n");
#endif
	return NUM_TOOLS;
}


/* --------------------- */
SDL_Surface * template_get_icon ( magic_api * api, int which )
{
	SDL_Surface *image;
	char fname[4096];

#ifdef DEBUG
	fprintf( stderr, "template_get_icon\n");
#endif

	snprintf ( fname, sizeof ( fname ), "%s/images/magic/%s",
	           api->data_directory, tools[which].icon_filename );
#ifdef DEBUG
	fprintf( stderr, "DEBUG: Loading image %s\n", fname);
#endif

	image = IMG_Load ( fname );
	if( !image) {
		fprintf( stderr, "IMG_Load( %s): %s\n", fname, IMG_GetError());
	}
	return image;
}


/* --------------------- */
char * template_get_name ( magic_api * api, int which )
{
	const char * our_name_english;
	const char * our_name_localized;

#ifdef DEBUG
	fprintf( stderr, "template_get_name\n");
#endif
	our_name_english = tools[which].name;
	our_name_localized = gettext ( our_name_english );
	return strdup ( our_name_localized );
}

/* --------------------- */
char * template_get_description ( magic_api * api, int which, int mode )
{
	const char * our_desc_english;
	const char * our_desc_localized;

#ifdef DEBUG
	fprintf( stderr, "template_get_description\n");
#endif
	our_desc_english = tools[which].desc;
	our_desc_localized = gettext ( our_desc_english );
	return strdup ( our_desc_localized );
}

/* --------------------- */
int template_requires_colors ( magic_api * api, int which )
{
	return 0;	// FALSE
}

/* --------------------- */
int template_modes ( magic_api * api, int which )
{
	return MODE_FULLSCREEN;
}


// Shut down
//
// explain how SDL_audioin could be patched to make Open/CloseAudioIn work
// symmetrically for the DEVDSP (Linux) driver

/* --------------------- */
void template_shutdown ( magic_api * api )
{
#ifdef DEBUG
	fprintf( stderr, "template_shutdown\n");
#endif
}


/* --------------------- */
void template_click ( magic_api * api, int which, int mode,
                     SDL_Surface * canvas, SDL_Surface * snapshot,
                     int x, int y, SDL_Rect * update_rect )
{
#ifdef DEBUG
	fprintf( stderr, "template_click\n");
#endif
}


/* --------------------- */
void template_drag ( magic_api * api, int which, SDL_Surface * canvas,
                    SDL_Surface * snapshot, int ox, int oy, int x, int y,
                    SDL_Rect * update_rect )
{
#ifdef DEBUG
	fprintf( stderr, "template_drag\n");
#endif
}


/* --------------------- */
void template_release ( magic_api * api, int which,
                       SDL_Surface * canvas, SDL_Surface * snapshot,
                       int x, int y, SDL_Rect * update_rect )
{
#ifdef DEBUG
	fprintf( stderr, "template_release\n");
#endif
}


/* --------------------- */
void template_set_color ( magic_api * api, Uint8 r, Uint8 g, Uint8 b )
{
	// this tool uses no color
}

/* --------------------- */
void template_switchin ( magic_api * api, int which, int mode, SDL_Surface * canvas )
{
#ifdef DEBUG
	fprintf( stderr, "template_switchin\n");
#endif
	return;
}

/* --------------------- */
void template_switchout ( magic_api * api, int which, int mode, SDL_Surface * canvas )
{
#ifdef DEBUG
	fprintf( stderr, "template_switchout\n");
#endif
	return;
}

